home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gnulib / libsrc98.zoo / ioctl.c < prev    next >
C/C++ Source or Header  |  1992-03-22  |  2KB  |  110 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  *  A simple hack for ioctl - note that some fields of the structures are not
  6.  * filled in.
  7.  *
  8.  */
  9. #include    <ioctl.h>
  10. #include    <errno.h>
  11. #include    <tchars.h>
  12. #include     <osbind.h>
  13. #include    <device.h>
  14. #include    <unistd.h>
  15. #include    <linea.h>    /* for TIOCGWINSZ under TOS */
  16.  
  17. int
  18. ioctl(fd, func, arg)
  19.     int    fd;
  20.     int    func;
  21.     void    *arg;
  22. {
  23.     struct sgttyb    *sg;
  24.     struct tchars    *tc;
  25.     struct ltchars    *ltc;
  26.     struct _device    *dev;
  27.  
  28.     if ((dev = _dev_fd(fd)) && dev->ioctl)
  29.         return (*dev->ioctl)(fd, func, arg);
  30.  
  31.     if (!isatty(fd)) {
  32.         errno = ENOTTY;
  33.         return -1;
  34.     }
  35.     switch (func) {
  36.     case TIOCGETP:
  37.         sg = (struct sgttyb *) arg;
  38.         sg->sg_ispeed = sg->sg_ospeed = B4800;
  39.         sg->sg_erase = __tchars[TC_ERASE];
  40.         sg->sg_kill = __tchars[TC_KILL];
  41.         sg->sg_flags = __ttymode;
  42.         break;
  43.  
  44.     case TIOCSETP:
  45.         sg = (struct sgttyb *) arg;
  46.         __tchars[TC_ERASE] = sg->sg_erase;
  47.         __tchars[TC_KILL] = sg->sg_kill;
  48.         __ttymode = sg->sg_flags;
  49.         break;
  50.  
  51.     case TIOCGETC:
  52.         tc = (struct tchars *) arg;
  53.         tc->t_intrc = __tchars[TC_INTRC];
  54.         tc->t_quitc = __tchars[TC_QUITC];
  55.         tc->t_startc = TC_UNDEF;
  56.         tc->t_stopc = TC_UNDEF;
  57.         tc->t_eofc = __tchars[TC_EOFC];
  58.         tc->t_brkc = __tchars[TC_BRKC];
  59.         break;
  60.  
  61.     case TIOCSETC:
  62.         tc = (struct tchars *) arg;
  63.         __tchars[TC_INTRC] = tc->t_intrc;
  64.         __tchars[TC_QUITC] = tc->t_quitc;
  65.         __tchars[TC_EOFC] = tc->t_eofc;
  66.         __tchars[TC_BRKC] = tc->t_brkc;
  67.         break;
  68.  
  69.     case TIOCGLTC:
  70.         ltc = (struct ltchars *) arg;
  71.         ltc->t_suspc = TC_UNDEF;
  72.         ltc->t_dsuspc = TC_UNDEF;
  73.         ltc->t_rprntc = __tchars[TC_RPRNTC];
  74.         ltc->t_flushc = TC_UNDEF;
  75.         ltc->t_werasc = __tchars[TC_WERASC];
  76.         ltc->t_lnextc = __tchars[TC_LNEXTC];
  77.         break;
  78.  
  79.     case TIOCSLTC:
  80.         ltc = (struct ltchars *) arg;
  81.         __tchars[TC_RPRNTC] = ltc->t_rprntc;
  82.         __tchars[TC_WERASC] = ltc->t_werasc;
  83.         __tchars[TC_LNEXTC] = ltc->t_lnextc;
  84.         break;
  85.  
  86.     case TIOCSWINSZ:
  87.             break;
  88.  
  89.     case TIOCGWINSZ:
  90.         {
  91.         struct winsize *win = (struct winsize *)arg;
  92.  
  93. #ifndef __SOZOBON__
  94.             (void)linea0();
  95. #else /* __SOZOBON__ */
  96.             linea0();
  97. #endif /* __SOZOBON__ */
  98.         win->ws_row = V_CEL_MY + 1;
  99.         win->ws_col = V_CEL_MX + 1;
  100.         win->ws_xpixel = V_X_MAX;
  101.         win->ws_ypixel = V_Y_MAX;
  102.         }
  103.  
  104.     default:
  105.         errno = EINVAL;
  106.         return -1;
  107.     }
  108.     return 0;
  109. }
  110.